package blog

import (
	"dustbe/database"
	"fmt"
	"net/http"

	"github.com/gin-gonic/gin"
)

func SearchBlogsByNames(c *gin.Context) {
	names := c.Query("names")
	if len(names) == 0 {
		c.JSON(http.StatusBadRequest, gin.H{"code": 4001, "data": "输入不能为空"})
		return
	}
	blogs, err := database.SearchBlogsByName(names)
	if err != nil {
		fmt.Println(err.Error())
		c.JSON(http.StatusOK, gin.H{"code": 4001, "data": "搜索时发生错误 " + err.Error()})
		return
	}

	c.JSON(http.StatusOK, gin.H{"code": 200, "data": blogs})
}
